use clap::Parser;
use tracing::{info, error};

// 使用本地路径导入
use crate::config::Settings;
use crate::api::ChatGLMClient;
use crate::converter::CodeConverter;
use crate::error::Result;

mod api;
mod config;
mod converter;
mod error;
mod utils;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[arg(short, long, value_name = "CONFIG")]
    config: Option<String>,
}

#[tokio::main]
async fn main() -> Result<()> {
    // 初始化日志
    tracing_subscriber::fmt::init();

    // 解析命令行参数
    let cli = Cli::parse();

    // 加载配置
    let settings = Settings::new()?;
    
    // 初始化API客户端
    let api_client = ChatGLMClient::new(settings.api.clone())?;
    
    // 创建转换器
    let converter = CodeConverter::new(settings, api_client);

    // 执行转换
    match converter.convert_all().await {
        Ok(_) => info!("Conversion completed successfully"),
        Err(e) => error!("Conversion failed: {}", e),
    }

    Ok(())
} 